[IOEMU] Locking needed to access mapcache.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 13 Dec 2006 11:01:33 +0000 (11:01 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 13 Dec 2006 11:01:33 +0000 (11:01 +0000)
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/ioemu/target-i386-dm/exec-dm.c
tools/ioemu/vl.c

index 755d54777237189b26c828db8a613cb27cf04ebf..08911564a19a0f1c15d6fbc52adbe29f6f5f3c78 100644 (file)
@@ -439,7 +439,12 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
     int l, io_index;
     uint8_t *ptr;
     uint32_t val;
-    
+
+#if defined(__i386__) || defined(__x86_64__)
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    pthread_mutex_lock(&mutex);
+#endif
+
     while (len > 0) {
         /* How much can we copy before the next page boundary? */
         l = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); 
@@ -504,6 +509,10 @@ void cpu_physical_memory_rw(target_phys_addr_t addr, uint8_t *buf,
         buf += l;
         addr += l;
     }
+
+#if defined(__i386__) || defined(__x86_64__)
+    pthread_mutex_unlock(&mutex);
+#endif
 }
 #endif
 
index e14e6a1d9eb3c50b6f72c442b95ad1e370fea903..6fc10c818792659d6158bb749e0e9447ac23b8cf 100644 (file)
@@ -5820,8 +5820,8 @@ static int qemu_map_cache_init(unsigned long nr_pages)
     if (nr_pages < max_pages)
         max_pages = nr_pages;
 
-    nr_buckets = (max_pages << PAGE_SHIFT) >> MCACHE_BUCKET_SHIFT;
-
+    nr_buckets   = max_pages + (1UL << (MCACHE_BUCKET_SHIFT - PAGE_SHIFT)) - 1;
+    nr_buckets >>= (MCACHE_BUCKET_SHIFT - PAGE_SHIFT);
     fprintf(logfile, "qemu_map_cache_init nr_buckets = %lx\n", nr_buckets);
 
     mapcache_entry = malloc(nr_buckets * sizeof(struct map_cache));
@@ -5857,8 +5857,7 @@ uint8_t *qemu_map_cache(target_phys_addr_t phys_addr)
 
     entry = &mapcache_entry[address_index % nr_buckets];
 
-    if (entry->vaddr_base == NULL || entry->paddr_index != address_index)
-    { 
+    if (entry->vaddr_base == NULL || entry->paddr_index != address_index) {
         /* We need to remap a bucket. */
         uint8_t *vaddr_base;
         unsigned long pfns[MCACHE_BUCKET_SIZE >> PAGE_SHIFT];